<template>
  <el-drawer
    title="选择主题颜色"
    custom-class="theme-selector"
    :visible.sync="theme_model"
    :show-close="false"
    size="20%"
  >
    <div
      @click="changeThen(item.name)"
      class="item"
      :title="item.title"
      v-for="(item, index) in theme_color"
      :key="index"
      :style="{ background: item.color }"
    ></div>
  </el-drawer>
</template>

<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: {},
    },
  },
  watch: {
    value(newVal, oldVal) {
      this.theme_model = true;
    },
  },
  data() {
    return {
      theme_model: false,
      theme_color: [
        {
          name: "dark",
          title: "五彩斑斓的黑",
          color: "#333744",
        },
        {
          name: "blue",
          title: "蓝色经典",
          color: "rgb(45, 140, 240)",
        },
        {
          name: "red",
          title: "夕阳红",
          color: "rgb(237, 64, 20)",
        },
        {
          name: "orange",
          title: "金橙传说",
          color: "rgb(255, 153, 0)",
        },
        {
          name: "pink",
          title: "骚粉色",
          color: "rgb(255, 192, 203)",
        },
        {
          name: "green",
          title: "当然是选择原谅",
          color: "rgb(25, 190, 107)",
        },
      ],
    };
  },
  methods: {
    changeThen(name) {
      this.$store.commit("SET_THEME", name);
    },
  },
};
</script>

<style lang="less">
.theme-selector {
  .el-drawer__header {
    border-bottom: 1px solid #e8eaec;
    padding: 14px 16px;
    line-height: 1;
    margin-bottom: 0px;
    span {
      display: inline-block;
      width: 100%;
      height: 20px;
      line-height: 20px;
      font-size: 14px;
      color: #17233d;
      font-weight: 700;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .el-drawer__body {
    width: 100%;
    height: calc(100% - 51px);
    padding: 16px;
    font-size: 12px;
    line-height: 1.5;
    word-wrap: break-word;
    // position: absolute;
    overflow: auto;
    .item {
      cursor: pointer;
      width: 100%;
      height: 80px;
      border-radius: 5px;
      margin-bottom: 17px;
      border: 1px solid #d4d2d2;
    }
  }
}
</style>